/*      */ package com.zimbra.qa.unittest;
/*      */ 
/*      */ import com.google.common.collect.Maps;
/*      */ import com.zimbra.common.account.Key.AccountBy;
/*      */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*      */ import com.zimbra.common.account.Key.CosBy;
/*      */ import com.zimbra.common.account.Key.DistributionListBy;
/*      */ import com.zimbra.common.account.Key.DomainBy;
/*      */ import com.zimbra.common.account.Key.ServerBy;
/*      */ import com.zimbra.common.localconfig.LC;
/*      */ import com.zimbra.common.localconfig.LC.PUBLIC_SHARE_VISIBILITY;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.util.Log;
/*      */ import com.zimbra.common.util.ZimbraLog;
/*      */ import com.zimbra.cs.account.Account;
/*      */ import com.zimbra.cs.account.CalendarResource;
/*      */ import com.zimbra.cs.account.Cos;
/*      */ import com.zimbra.cs.account.DistributionList;
/*      */ import com.zimbra.cs.account.Domain;
/*      */ import com.zimbra.cs.account.Identity;
/*      */ import com.zimbra.cs.account.Provisioning;
/*      */ import com.zimbra.cs.account.Provisioning.RightsDoc;
/*      */ import com.zimbra.cs.account.Server;
/*      */ import com.zimbra.cs.account.accesscontrol.Right;
/*      */ import com.zimbra.cs.account.accesscontrol.RightClass;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.AllEffectiveRights;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.MailboxInfo;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning.ReIndexInfo;
/*      */ import com.zimbra.soap.admin.message.GetLicenseInfoRequest;
/*      */ import com.zimbra.soap.admin.message.GetLicenseInfoResponse;
/*      */ import com.zimbra.soap.admin.message.GetServerNIfsRequest;
/*      */ import com.zimbra.soap.admin.message.GetServerNIfsResponse;
/*      */ import com.zimbra.soap.admin.message.GetVersionInfoRequest;
/*      */ import com.zimbra.soap.admin.message.GetVersionInfoResponse;
/*      */ import com.zimbra.soap.admin.message.ModifyCosRequest;
/*      */ import com.zimbra.soap.admin.message.ModifyCosResponse;
/*      */ import com.zimbra.soap.admin.type.CacheEntryType;
/*      */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*      */ import com.zimbra.soap.admin.type.LicenseExpirationInfo;
/*      */ import com.zimbra.soap.admin.type.VersionInfo;
/*      */ import com.zimbra.soap.mail.message.CreateFolderRequest;
/*      */ import com.zimbra.soap.mail.message.CreateFolderResponse;
/*      */ import com.zimbra.soap.mail.message.CreateMountpointRequest;
/*      */ import com.zimbra.soap.mail.message.CreateMountpointResponse;
/*      */ import com.zimbra.soap.mail.message.FolderActionRequest;
/*      */ import com.zimbra.soap.mail.message.FolderActionResponse;
/*      */ import com.zimbra.soap.mail.type.ActionGrantSelector;
/*      */ import com.zimbra.soap.mail.type.FolderActionSelector;
/*      */ import com.zimbra.soap.mail.type.NewFolderSpec;
/*      */ import com.zimbra.soap.mail.type.NewMountpointSpec;
/*      */ import com.zimbra.soap.type.AccountSelector;
/*      */ import com.zimbra.soap.type.GranteeChooser;
/*      */ import com.zimbra.soap.type.ShareInfo;
/*      */ import java.util.List;
/*      */ import java.util.Map;
/*      */ import java.util.Set;
/*      */ import org.junit.Assert;
/*      */ import org.junit.Test;
/*      */ import org.junit.rules.TestName;
/*      */ 
/*      */ public class TestJaxbProvisioning extends junit.framework.TestCase
/*      */ {
/*      */   @org.junit.Rule
/*      */   public TestName testName;
/*      */   private SoapProvisioning prov;
/*      */   private static final String domain1 = "jaxb.domain1";
/*      */   private static final String domain2 = "jaxb.domain2";
/*      */   private static final String domain3 = "jaxb.domain3";
/*      */   private static final String sharer = "sharer@jaxb.domain1";
/*      */   private static final String sharee = "sharee@jaxb.domain1";
/*      */   private static final String other = "other@jaxb.domain1";
/*      */   private static final String dom2acct = "dom2acct@jaxb.domain2";
/*      */   private static final String dom3acct = "dom3acct@jaxb.domain3";
/*      */   private static final String testServer = "jaxb.server.example.test";
/*      */   private static final String testAcctEmail = "jaxb1@jaxb.domain2";
/*      */   private static final String dom1acct = "dom1acct@jaxb.domain2";
/*      */   private static final String testAcctAlias = "alias_4_jaxb1@jaxb.domain2";
/*      */   private static final String testAcctIdentity = "identity_4_jaxb1@jaxb.domain2";
/*      */   private static final String testNewAcctEmail = "new_jaxb1@jaxb.domain2";
/*      */   private static final String testCalResDomain = "jaxb.calr.domain.example.test";
/*      */   private static final String testCalRes = "jaxb1@jaxb.calr.domain.example.test";
/*      */   private static final String testNewCalRes = "new_jaxb1@jaxb.calr.domain.example.test";
/*      */   private static final String testCalResDisplayName = "JAXB Test CalResource";
/*      */   private static final String testDlDomain = "jaxb.dl.domain.example.test";
/*      */   private static final String testDl = "jaxb_dl1@jaxb.dl.domain.example.test";
/*      */   private static final String parentDl = "jaxb_parentdl@jaxb.dl.domain.example.test";
/*      */   private static final String testDlAlias = "alias_4_jaxb_dl1@jaxb.dl.domain.example.test";
/*      */   private static final String testDlNewName = "new_jaxb_dl1@jaxb.dl.domain.example.test";
/*      */   private static final String testCosDomain = "jaxb.cos.domain.example.test";
/*      */   private static final String testCos = "jaxb_cos@jaxb.dl.domain.example.test";
/*      */   private static final String testCosCopy = "jaxb_cos_copy@jaxb.dl.domain.example.test";
/*      */   private static final String testNewCos = "new_jaxb_cos@jaxb.dl.domain.example.test";
/*      */   
/*      */   public TestJaxbProvisioning()
/*      */   {
/*   97 */     this.testName = new TestName();
/*      */     
/*   99 */     this.prov = null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void init()
/*      */     throws Exception
/*      */   {
/*  131 */     oneTimeTearDown();
/*      */   }
/*      */   
/*      */   public void oneTimeTearDown() {
/*  135 */     ZimbraLog.test.info("in TestJaxbProvisioning oneTimeTearDown");
/*      */   }
/*      */   
/*      */   public void setUp() throws Exception
/*      */   {
/*  140 */     if (!TestUtil.fromRunUnitTests) {
/*  141 */       TestUtil.cliSetup();
/*      */     }
/*  143 */     this.prov = TestUtil.newSoapProvisioning();
/*  144 */     tearDown();
/*      */   }
/*      */   
/*      */   public void tearDown() throws Exception
/*      */   {
/*  149 */     ZimbraLog.test.debug("in TestJaxbProvisioning tearDown");
/*  150 */     if (this.prov == null) {
/*  151 */       this.prov = TestUtil.newSoapProvisioning();
/*      */     }
/*  153 */     TestUtil.setLCValue(LC.public_share_advertising_scope, null);
/*  154 */     TestUtil.deleteAccount("jaxb1@jaxb.domain2");
/*  155 */     TestUtil.deleteAccount("new_jaxb1@jaxb.domain2");
/*  156 */     TestUtil.deleteAccount("sharer@jaxb.domain1");
/*  157 */     TestUtil.deleteAccount("sharee@jaxb.domain1");
/*  158 */     TestUtil.deleteAccount("other@jaxb.domain1");
/*  159 */     TestUtil.deleteAccount("dom1acct@jaxb.domain2");
/*  160 */     TestUtil.deleteAccount("dom2acct@jaxb.domain2");
/*  161 */     TestUtil.deleteAccount("dom3acct@jaxb.domain3");
/*  162 */     deleteCalendarResourceIfExists("jaxb1@jaxb.calr.domain.example.test");
/*  163 */     deleteDlIfExists("jaxb_dl1@jaxb.dl.domain.example.test");
/*  164 */     deleteDlIfExists("jaxb_parentdl@jaxb.dl.domain.example.test");
/*  165 */     deleteDlIfExists("new_jaxb_dl1@jaxb.dl.domain.example.test");
/*  166 */     deleteCosIfExists("jaxb_cos@jaxb.dl.domain.example.test");
/*  167 */     deleteCosIfExists("new_jaxb_cos@jaxb.dl.domain.example.test");
/*  168 */     deleteCosIfExists("jaxb_cos_copy@jaxb.dl.domain.example.test");
/*  169 */     deleteDomainIfExists("jaxb.domain1");
/*  170 */     deleteDomainIfExists("jaxb.calr.domain.example.test");
/*  171 */     deleteDomainIfExists("jaxb.dl.domain.example.test");
/*  172 */     deleteDomainIfExists("jaxb.cos.domain.example.test");
/*  173 */     deleteDomainIfExists("jaxb.domain2");
/*  174 */     deleteDomainIfExists("jaxb.domain3");
/*  175 */     deleteServerIfExists("jaxb.server.example.test");
/*      */   }
/*      */   
/*      */   private String testName() {
/*  179 */     return this.testName.getMethodName();
/*      */   }
/*      */   
/*      */   public static void deleteAccountIfExists(String name) {
/*      */     try {
/*  184 */       ZimbraLog.test.debug("Deleting Account %s", new Object[] { name });
/*  185 */       Provisioning prov = TestUtil.newSoapProvisioning();
/*  186 */       Account acc = prov.get(Key.AccountBy.name, name);
/*  187 */       if (acc != null) {
/*  188 */         prov.deleteAccount(acc.getId());
/*      */       }
/*      */     } catch (Exception ex) {
/*  191 */       ZimbraLog.test.error("Problem deleting Account %s", name, ex);
/*      */     }
/*      */   }
/*      */   
/*      */   public static void deleteDomainIfExists(String name) {
/*  196 */     try { ZimbraLog.test.debug("Deleting domain %s", new Object[] { name });
/*  197 */       Provisioning prov = TestUtil.newSoapProvisioning();
/*  198 */       Domain res = prov.get(Key.DomainBy.name, name);
/*  199 */       if (res != null) {
/*  200 */         prov.deleteDomain(res.getId());
/*      */       }
/*      */     } catch (Exception ex) {
/*  203 */       ZimbraLog.test.error("Problem deleting domain %s", name, ex);
/*      */     }
/*      */   }
/*      */   
/*      */   public static void deleteServerIfExists(String name) {
/*      */     try {
/*  209 */       ZimbraLog.test.debug("Deleting server %s", new Object[] { name });
/*  210 */       Provisioning prov = TestUtil.newSoapProvisioning();
/*  211 */       Server res = prov.get(Key.ServerBy.name, name);
/*  212 */       if (res != null) {
/*  213 */         prov.deleteServer(res.getId());
/*      */       }
/*      */     } catch (Exception ex) {
/*  216 */       ZimbraLog.test.error("Problem deleting server %s", name, ex);
/*      */     }
/*      */   }
/*      */   
/*      */   public static void deleteCalendarResourceIfExists(String name) {
/*      */     try {
/*  222 */       ZimbraLog.test.debug("Deleting CalendarResource %s", new Object[] { name });
/*  223 */       Provisioning prov = TestUtil.newSoapProvisioning();
/*  224 */       CalendarResource res = prov.get(Key.CalendarResourceBy.name, name);
/*  225 */       if (res != null) {
/*  226 */         prov.deleteDomain(res.getId());
/*      */       }
/*      */     } catch (Exception ex) {
/*  229 */       ZimbraLog.test.error("Problem deleting Calendar Resource %s", name, ex);
/*      */     }
/*      */   }
/*      */   
/*      */   public static void deleteDlIfExists(String name) {
/*      */     try {
/*  235 */       ZimbraLog.test.debug("Deleting DL %s", new Object[] { name });
/*  236 */       Provisioning prov = TestUtil.newSoapProvisioning();
/*  237 */       DistributionList res = prov.get(Key.DistributionListBy.name, name);
/*  238 */       if (res != null) {
/*  239 */         prov.deleteDistributionList(res.getId());
/*      */       }
/*      */     } catch (Exception ex) {
/*  242 */       ZimbraLog.test.error("Problem deleting Distribution List %s", name, ex);
/*      */     }
/*      */   }
/*      */   
/*      */   public static void deleteCosIfExists(String name) {
/*      */     try {
/*  248 */       ZimbraLog.test.debug("Deleting COS %s", new Object[] { name });
/*  249 */       Provisioning prov = TestUtil.newSoapProvisioning();
/*  250 */       Cos res = prov.get(Key.CosBy.name, name);
/*  251 */       if (res != null)
/*  252 */         prov.deleteCos(res.getId());
/*      */     } catch (Exception ex) {
/*  254 */       ZimbraLog.test.error("Problem deleting Cos %s", name, ex);
/*      */     }
/*      */   }
/*      */   
/*      */   public static Domain ensureDomainExists(String name) throws Exception
/*      */   {
/*  260 */     Provisioning prov = TestUtil.newSoapProvisioning();
/*  261 */     Domain dom = prov.get(Key.DomainBy.name, name);
/*  262 */     if (dom == null) {
/*  263 */       ZimbraLog.test.debug("ensureDomainExists didn't exist - creating new domain=%s", new Object[] { name });
/*  264 */       dom = prov.createDomain(name, null);
/*      */     }
/*  266 */     if (dom == null) {
/*  267 */       ZimbraLog.test.debug("ensureDomainExists returning null!!!");
/*      */     } else {
/*  269 */       ZimbraLog.test.debug("ensureDomainExists Returning=%s Id=%s", new Object[] { dom.getName(), dom.getId() });
/*      */     }
/*  271 */     return dom;
/*      */   }
/*      */   
/*      */   public static Account ensureAccountExists(String name) throws Exception
/*      */   {
/*  276 */     String domainName = name.substring(name.indexOf('@') + 1);
/*  277 */     ensureDomainExists(domainName);
/*  278 */     Provisioning prov = TestUtil.newSoapProvisioning();
/*  279 */     Account acct = prov.get(Key.AccountBy.name, name);
/*  280 */     if (acct == null)
/*  281 */       acct = TestUtil.createAccount(name);
/*  282 */     if (acct == null) {
/*  283 */       ZimbraLog.test.debug("ensureAccountExists returning null!!!");
/*      */     } else {
/*  285 */       ZimbraLog.test.debug("ensureAccountExists Returning Account=%s Id=%s", new Object[] { acct.getName(), acct.getId() });
/*      */     }
/*  287 */     return acct;
/*      */   }
/*      */   
/*      */   public static Account ensureMailboxExists(String name) throws Exception
/*      */   {
/*  292 */     SoapProvisioning prov = TestUtil.newSoapProvisioning();
/*  293 */     Account acct = ensureAccountExists(name);
/*  294 */     if (acct == null) {
/*  295 */       ZimbraLog.test.debug("ensureMailboxExists returning null!!!");
/*      */ 
/*      */     }
/*      */     else
/*      */     {
/*  300 */       SoapProvisioning.MailboxInfo mboxInfo = prov.getMailbox(acct);
/*  301 */       ZimbraLog.test.debug("ensureMailboxExists Returning Mailbox=%s Account=%s Id=%s", new Object[] { mboxInfo.getMailboxId(), acct.getName(), acct.getId() });
/*      */     }
/*      */     
/*  304 */     return acct;
/*      */   }
/*      */   
/*      */   public static DistributionList ensureDlExists(String name) throws Exception
/*      */   {
/*  309 */     Provisioning prov = TestUtil.newSoapProvisioning();
/*  310 */     String domainName = name.substring(name.indexOf('@') + 1);
/*  311 */     ensureDomainExists(domainName);
/*  312 */     DistributionList dl = prov.get(Key.DistributionListBy.name, name);
/*  313 */     if (dl == null) {
/*  314 */       dl = prov.createDistributionList(name, null);
/*      */     }
/*  316 */     return dl;
/*      */   }
/*      */   
/*      */   public static Cos ensureCosExists(String name) throws Exception
/*      */   {
/*  321 */     Provisioning prov = TestUtil.newSoapProvisioning();
/*  322 */     String domainName = name.substring(name.indexOf('@') + 1);
/*  323 */     ensureDomainExists(domainName);
/*  324 */     Cos cos = prov.get(Key.CosBy.name, name);
/*  325 */     if (cos == null) {
/*  326 */       cos = prov.createCos(name, null);
/*      */     }
/*  328 */     return cos;
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testGetConfig() throws Exception {
/*  333 */     ZimbraLog.test.debug("Starting test %s", new Object[] { testName() });
/*  334 */     com.zimbra.cs.account.Config cfg = this.prov.getConfig();
/*  335 */     assertNotNull("Config", cfg);
/*  336 */     cfg = this.prov.getConfig("zimbra_user");
/*  337 */     assertNotNull("Config", cfg);
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testServer() throws Exception {
/*  342 */     ZimbraLog.test.debug("Starting test %s", new Object[] { testName() });
/*  343 */     Domain dom = ensureDomainExists("jaxb.server.example.test");
/*  344 */     assertNotNull("Domain for jaxb.domain1", dom);
/*  345 */     Server svr = this.prov.createServer("jaxb.server.example.test", null);
/*  346 */     assertNotNull("Server for jaxb.server.example.test", svr);
/*  347 */     svr = this.prov.get(Key.ServerBy.id, svr.getId());
/*  348 */     List<Server> svrs = this.prov.getAllServers();
/*  349 */     assertNotNull("All Servers", svrs);
/*  350 */     assertTrue("Number of Servers objects=" + svrs.size() + " should be >=1", svrs.size() >= 1);
/*      */     
/*  352 */     this.prov.deleteServer(svr.getId());
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testAccount() throws Exception {
/*  357 */     ZimbraLog.test.debug("Starting testAccount");
/*  358 */     Domain dom = ensureDomainExists("jaxb.domain2");
/*  359 */     assertNotNull("Domain for jaxb.domain2", dom);
/*  360 */     Account acct = this.prov.createAccount("jaxb1@jaxb.domain2", "test123", null);
/*      */     
/*  362 */     this.prov.authAccount(acct, "test123", com.zimbra.cs.account.auth.AuthContext.Protocol.test);
/*      */     
/*  364 */     assertNotNull("Account for jaxb1@jaxb.domain2", acct);
/*  365 */     this.prov.changePassword(acct, "test123", "DelTA4Pa555");
/*  366 */     this.prov.checkPasswordStrength(acct, "2ndDelTA4Pa555");
/*  367 */     this.prov.setPassword(acct, "2ndDelTA4Pa555");
/*  368 */     this.prov.renameAccount(acct.getId(), "new_jaxb1@jaxb.domain2");
/*  369 */     this.prov.addAlias(acct, "alias_4_jaxb1@jaxb.domain2");
/*  370 */     this.prov.removeAlias(acct, "alias_4_jaxb1@jaxb.domain2");
/*  371 */     acct = this.prov.get(Key.AccountBy.name, "new_jaxb1@jaxb.domain2");
/*  372 */     assertNotNull("Account for new_jaxb1@jaxb.domain2", acct);
/*  373 */     com.zimbra.cs.account.soap.SoapAccountInfo acctInfo = this.prov.getAccountInfo(Key.AccountBy.id, acct.getId());
/*  374 */     assertNotNull("SoapAccountInfo for new_jaxb1@jaxb.domain2", acctInfo);
/*  375 */     acct = this.prov.get(Key.AccountBy.name, "new_jaxb1@jaxb.domain2", true);
/*  376 */     assertNotNull("2nd Account for new_jaxb1@jaxb.domain2", acct);
/*  377 */     List<Account> adminAccts = this.prov.getAllAdminAccounts(true);
/*  378 */     assertNotNull("Admin Accounts", adminAccts);
/*  379 */     assertTrue("Number of Admin Account objects=" + adminAccts.size() + " should be >=1", adminAccts.size() >= 1);
/*      */     
/*  381 */     List<Account> accts = this.prov.getAllAccounts(dom);
/*  382 */     assertNotNull("All Accounts", accts);
/*  383 */     assertTrue("Number of Account objects=" + accts.size() + " should be >=1", accts.size() >= 1);
/*      */     
/*  385 */     List<Domain> domains = this.prov.getAllDomains(false);
/*  386 */     assertNotNull("All Domains", domains);
/*  387 */     assertTrue("Number of Domain objects=" + domains.size() + " should be >=1", domains.size() >= 1);
/*      */     
/*  389 */     dom = this.prov.get(Key.DomainBy.id, dom.getId());
/*  390 */     assertNotNull("Domain got by id", dom);
/*  391 */     com.zimbra.cs.account.Provisioning.CountAccountResult res = this.prov.countAccount(dom);
/*  392 */     assertNotNull("CountAccountResult", res);
/*  393 */     dom = this.prov.getDomainInfo(Key.DomainBy.id, dom.getId());
/*  394 */     assertNotNull("DomainInfo got by id", dom);
/*      */     
/*  396 */     this.prov.deleteAccount(acct.getId());
/*      */   }
/*      */   
/*      */   public static class CutDownShareInfo {
/*      */     String folderPath;
/*      */     String ownerEmail;
/*      */     String granteeType;
/*      */     
/*  404 */     public CutDownShareInfo(String folderPath, String ownerEmail, String granteeType) { this.folderPath = folderPath;
/*  405 */       this.ownerEmail = ownerEmail;
/*  406 */       this.granteeType = granteeType;
/*      */     }
/*      */     
/*  409 */     public CutDownShareInfo(ShareInfo sInfo) { this.folderPath = sInfo.getFolderPath();
/*  410 */       this.ownerEmail = sInfo.getOwnerEmail();
/*  411 */       this.granteeType = sInfo.getGranteeType();
/*      */     }
/*      */     
/*      */     public boolean matches(ShareInfo shareInfo) {
/*  415 */       return (this.folderPath.equals(shareInfo.getFolderPath())) && (this.ownerEmail.equals(shareInfo.getOwnerEmail())) && (this.granteeType.equals(shareInfo.getGranteeType()));
/*      */     }
/*      */     
/*      */     public String toString()
/*      */     {
/*  420 */       return String.format("path=%s ownerEmail=%s granteeType=%s", new Object[] { this.folderPath, this.ownerEmail, this.granteeType });
/*      */     }
/*      */   }
/*      */   
/*      */   public static class ShareSet {
/*  425 */     Set<TestJaxbProvisioning.CutDownShareInfo> shares = com.google.common.collect.Sets.newHashSet();
/*      */     
/*      */     public ShareSet() {}
/*      */     
/*      */     public ShareSet(TestJaxbProvisioning.CutDownShareInfo share) {
/*  430 */       add(share);
/*      */     }
/*      */     
/*      */     public ShareSet(Set<TestJaxbProvisioning.CutDownShareInfo> shares) {
/*  434 */       addAll(shares);
/*      */     }
/*      */     
/*      */     public ShareSet add(TestJaxbProvisioning.CutDownShareInfo share) {
/*  438 */       this.shares.add(share);
/*  439 */       return this;
/*      */     }
/*      */     
/*      */     public ShareSet addAll(Set<TestJaxbProvisioning.CutDownShareInfo> shars) {
/*  443 */       this.shares.addAll(shars);
/*  444 */       return this;
/*      */     }
/*      */     
/*      */     public ShareSet addAll(List<ShareInfo> shars) {
/*  448 */       for (ShareInfo sInfo : shars) {
/*  449 */         this.shares.add(new TestJaxbProvisioning.CutDownShareInfo(sInfo));
/*      */       }
/*  451 */       return this;
/*      */     }
/*      */   }
/*      */   
/*      */   public CutDownShareInfo setupShare(Account sharerAccount, String sharerFolderName, byte color, String granteeType, Account shareeAccount, Account mountingAccount, String mountFolderName)
/*      */   {
/*  457 */     setupShare(sharerAccount, sharerFolderName, color, "appointment", granteeType, "r", shareeAccount, mountingAccount, mountFolderName);
/*      */     
/*  459 */     return new CutDownShareInfo("/" + sharerFolderName, sharerAccount.getName(), granteeType);
/*      */   }
/*      */   
/*      */   public void setupShare(Account sharerAccount, String sharerFolderName, byte color, String defaultView, String granteeType, String perm, Account shareeAccount, Account mountingAccount, String mountFolderName)
/*      */   {
/*  464 */     ShareInfo fred = new ShareInfo();
/*  465 */     fred.getGranteeType();
/*  466 */     String theSharee = shareeAccount != null ? shareeAccount.getName() : null;
/*  467 */     String folderId = createFolder(sharerAccount, sharerFolderName, Byte.valueOf(color), defaultView);
/*  468 */     grantAccess(sharerAccount, folderId, granteeType, theSharee, perm);
/*  469 */     if (mountingAccount != null) {
/*  470 */       createMountpoint(mountingAccount, mountFolderName, defaultView, sharerAccount.getId(), folderId);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   @Test
/*      */   public void testVisibilityNonePublicSharesConsistentlyIgnored()
/*      */     throws Exception
/*      */   {
/*  514 */     ZimbraLog.test.debug("Starting test %s", new Object[] { testName() });
/*      */     
/*  516 */     ensureDomainExists("jaxb.domain1");
/*  517 */     ensureDomainExists("jaxb.domain2");
/*  518 */     ensureDomainExists("jaxb.domain3");
/*  519 */     Cos cos = this.prov.createCos("jaxb_cos@jaxb.dl.domain.example.test", null);
/*  520 */     Assert.assertNotNull("Cos for jaxb_cos@jaxb.dl.domain.example.test", cos);
/*  521 */     Account sameDomAcct = ensureMailboxExists("sharer@jaxb.domain1");
/*  522 */     Account shareeAcct = ensureMailboxExists("sharee@jaxb.domain1");
/*  523 */     Account diffDomAcct = ensureMailboxExists("jaxb1@jaxb.domain2");
/*  524 */     Account diffDomAcct2 = ensureMailboxExists("new_jaxb1@jaxb.domain2");
/*  525 */     Account sameDomAcct3 = ensureMailboxExists("dom1acct@jaxb.domain2");
/*  526 */     Account diffDomAcct3 = ensureMailboxExists("dom2acct@jaxb.domain2");
/*  527 */     Account dom3acct1 = ensureMailboxExists("dom3acct@jaxb.domain3");
/*      */     
/*  529 */     shareeAcct.setCOSId(cos.getId());
/*  530 */     TestUtil.setLCValue(LC.public_share_advertising_scope, LC.PUBLIC_SHARE_VISIBILITY.none.toString());
/*  531 */     CutDownShareInfo pubDiffDom = setupShare(diffDomAcct, "PUB_DiffDomain", (byte)5, "pub", null, null, null);
/*  532 */     visibilityNoneRepeats(shareeAcct, diffDomAcct, diffDomAcct2, sameDomAcct);
/*  533 */     CutDownShareInfo pubSameDom = setupShare(sameDomAcct, "PUB_SameDomain", (byte)5, "pub", null, null, null);
/*  534 */     visibilityNoneRepeats(shareeAcct, diffDomAcct, diffDomAcct2, sameDomAcct);
/*      */     
/*  536 */     setupShare(diffDomAcct3, "USR_DiffDomain", (byte)3, "usr", sameDomAcct, null, null);
/*  537 */     accountGetShareInfo(sameDomAcct3, AccountSelector.fromName(diffDomAcct3.getName()), Boolean.valueOf(false), new ShareSet());
/*  538 */     accountGetShareInfo(sameDomAcct3, AccountSelector.fromId(diffDomAcct3.getId()), Boolean.valueOf(false), new ShareSet());
/*  539 */     setupShare(dom3acct1, "PUB_DiffDomain2", (byte)3, "pub", null, null, null);
/*  540 */     setupShare(dom3acct1, "USR_DiffDomain2", (byte)3, "usr", sameDomAcct, null, null);
/*  541 */     accountGetShareInfo(sameDomAcct3, AccountSelector.fromName(diffDomAcct3.getName()), Boolean.valueOf(false), new ShareSet());
/*  542 */     accountGetShareInfo(sameDomAcct3, AccountSelector.fromId(diffDomAcct3.getId()), Boolean.valueOf(false), new ShareSet());
/*  543 */     visibilityNoneRepeats(shareeAcct, diffDomAcct, diffDomAcct2, sameDomAcct);
/*      */   }
/*      */   
/*      */ 
/*      */   private void visibilityNoneRepeats(Account shareeAcct, Account diffDomAcct, Account diffDomAcct2, Account sameDomAcct)
/*      */   {
/*  549 */     accountGetShareInfo(shareeAcct, null, Boolean.valueOf(false), new ShareSet());
/*      */     
/*  551 */     accountGetShareInfo(shareeAcct, AccountSelector.fromName(diffDomAcct2.getName()), Boolean.valueOf(false), new ShareSet());
/*  552 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(diffDomAcct2.getId()), Boolean.valueOf(false), new ShareSet());
/*      */     
/*  554 */     accountGetShareInfo(shareeAcct, AccountSelector.fromName(diffDomAcct.getName()), Boolean.valueOf(false), new ShareSet());
/*  555 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(diffDomAcct.getId()), Boolean.valueOf(false), new ShareSet());
/*      */     
/*  557 */     accountGetShareInfo(shareeAcct, AccountSelector.fromName("nonexistent@jaxb.domain1"), Boolean.valueOf(false), new ShareSet());
/*      */     
/*      */ 
/*  560 */     accountGetShareInfo(shareeAcct, AccountSelector.fromName(sameDomAcct.getName()), Boolean.valueOf(false), new ShareSet());
/*  561 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(sameDomAcct.getId()), Boolean.valueOf(false), new ShareSet());
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testPublicSharesVisibility() throws Exception {
/*  566 */     ZimbraLog.test.debug("Starting test %s", new Object[] { testName() });
/*  567 */     ensureDomainExists("jaxb.domain1");
/*  568 */     ensureDomainExists("jaxb.domain2");
/*  569 */     Cos cos = this.prov.createCos("jaxb_cos@jaxb.dl.domain.example.test", null);
/*  570 */     Assert.assertNotNull("Cos for jaxb_cos@jaxb.dl.domain.example.test", cos);
/*  571 */     Account sameDomAcct = TestUtil.createAccount("sharer@jaxb.domain1");
/*  572 */     Account shareeAcct = ensureMailboxExists("sharee@jaxb.domain1");
/*  573 */     Account otherAcct = ensureMailboxExists("other@jaxb.domain1");
/*  574 */     Account diffDomAcct = TestUtil.createAccount("jaxb1@jaxb.domain2");
/*      */     
/*  576 */     shareeAcct.setCOSId(cos.getId());
/*  577 */     TestUtil.setLCValue(LC.public_share_advertising_scope, LC.PUBLIC_SHARE_VISIBILITY.all.toString());
/*  578 */     com.zimbra.soap.account.message.GetShareInfoResponse gsiResp = accountGetShareInfo(shareeAcct, null, Boolean.valueOf(false), null);
/*      */     
/*  580 */     ShareSet baselinePublicShares = new ShareSet().addAll(gsiResp.getShares());
/*      */     
/*  582 */     CutDownShareInfo mountedUsrSameDom = setupShare(sameDomAcct, "USER_Mounted", (byte)2, "usr", shareeAcct, shareeAcct, "USR_SAME_DOM");
/*      */     
/*  584 */     CutDownShareInfo notMountedUsrSameDom = setupShare(sameDomAcct, "USER_NOT_Mounted", (byte)3, "usr", shareeAcct, null, null);
/*      */     
/*  586 */     CutDownShareInfo mountedPubSameDom = setupShare(sameDomAcct, "PUB_Mounted", (byte)4, "pub", null, shareeAcct, "PUB_SAME_DOM");
/*      */     
/*  588 */     CutDownShareInfo notMountedPubSameDom = setupShare(sameDomAcct, "PUB_NOT_Mounted", (byte)5, "pub", null, null, null);
/*      */     
/*      */ 
/*  591 */     CutDownShareInfo usrUnrelatedSameDom = setupShare(sameDomAcct, "USER_Unrelated", (byte)2, "usr", otherAcct, null, null);
/*      */     
/*      */ 
/*  594 */     CutDownShareInfo mountedUsrDiffDom = setupShare(diffDomAcct, "USER_MountedDiffDom", (byte)2, "usr", shareeAcct, shareeAcct, "USR_DIFF_DOM");
/*      */     
/*  596 */     CutDownShareInfo notMountedUsrDiffDom = setupShare(diffDomAcct, "USER_NOT_MountedDiffDom", (byte)3, "usr", shareeAcct, null, null);
/*      */     
/*  598 */     CutDownShareInfo mountedPubDiffDom = setupShare(diffDomAcct, "PUB_MountedDiffDom", (byte)4, "pub", null, shareeAcct, "PUB_DIFF_DOM");
/*      */     
/*  600 */     CutDownShareInfo notMountedPubDiffDom = setupShare(diffDomAcct, "PUB_NOT_MountedDiffDom", (byte)5, "pub", null, null, null);
/*      */     
/*      */ 
/*  603 */     CutDownShareInfo usrUnrelatedDiffDom = setupShare(diffDomAcct, "USER_UnrelatedDiffDom", (byte)2, "usr", otherAcct, null, null);
/*      */     
/*      */ 
/*  606 */     ShareSet allMounted = new ShareSet(mountedUsrSameDom).add(mountedPubSameDom).add(mountedUsrDiffDom).add(mountedPubDiffDom);
/*      */     
/*  608 */     ShareSet allSharedSameDom = new ShareSet(mountedUsrSameDom).add(mountedPubSameDom).add(notMountedUsrSameDom).add(notMountedPubSameDom);
/*      */     
/*  610 */     ShareSet allSharedDiffDom = new ShareSet(mountedUsrDiffDom).add(mountedPubDiffDom).add(notMountedUsrDiffDom).add(notMountedPubDiffDom);
/*      */     
/*  612 */     ShareSet allShares = new ShareSet(allSharedSameDom.shares).addAll(allSharedDiffDom.shares);
/*      */     
/*  614 */     TestUtil.setLCValue(LC.public_share_advertising_scope, LC.PUBLIC_SHARE_VISIBILITY.samePrimaryDomain.toString());
/*  615 */     this.prov.flushCache(CacheEntryType.all, null);
/*  616 */     accountGetShareInfo(shareeAcct, null, Boolean.valueOf(false), new ShareSet(allMounted.shares).add(notMountedUsrSameDom).add(notMountedPubSameDom).add(notMountedUsrDiffDom));
/*      */     
/*      */ 
/*  619 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(sameDomAcct.getId()), Boolean.valueOf(false), new ShareSet(mountedUsrSameDom).add(mountedPubSameDom).add(notMountedPubSameDom).add(notMountedUsrSameDom));
/*      */     
/*      */ 
/*  622 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(diffDomAcct.getId()), Boolean.valueOf(false), new ShareSet(mountedUsrDiffDom).add(mountedPubDiffDom).add(notMountedUsrDiffDom));
/*      */     
/*  624 */     ShareSet adminSet = new ShareSet(allSharedSameDom.shares).add(usrUnrelatedSameDom);
/*  625 */     adminGetShareInfo(sameDomAcct, adminSet);
/*      */     
/*  627 */     TestUtil.setLCValue(LC.public_share_advertising_scope, LC.PUBLIC_SHARE_VISIBILITY.all.toString());
/*  628 */     this.prov.flushCache(CacheEntryType.account, null);
/*  629 */     accountGetShareInfo(shareeAcct, null, Boolean.valueOf(false), new ShareSet(baselinePublicShares.shares).addAll(allShares.shares));
/*      */     
/*  631 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(sameDomAcct.getId()), Boolean.valueOf(false), allSharedSameDom);
/*  632 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(diffDomAcct.getId()), Boolean.valueOf(false), allSharedDiffDom);
/*  633 */     adminGetShareInfo(sameDomAcct, adminSet);
/*      */     
/*  635 */     TestUtil.setLCValue(LC.public_share_advertising_scope, LC.PUBLIC_SHARE_VISIBILITY.none.toString());
/*  636 */     this.prov.flushCache(CacheEntryType.account, null);
/*  637 */     accountGetShareInfo(shareeAcct, null, Boolean.valueOf(false), new ShareSet(allMounted.shares).add(notMountedUsrSameDom).add(notMountedUsrDiffDom));
/*      */     
/*  639 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(sameDomAcct.getId()), Boolean.valueOf(false), new ShareSet(mountedUsrSameDom).add(mountedPubSameDom).add(notMountedUsrSameDom));
/*      */     
/*  641 */     accountGetShareInfo(shareeAcct, AccountSelector.fromId(diffDomAcct.getId()), Boolean.valueOf(false), new ShareSet(mountedUsrDiffDom).add(mountedPubDiffDom).add(notMountedUsrDiffDom));
/*      */     
/*  643 */     adminGetShareInfo(sameDomAcct, adminSet);
/*      */     
/*      */ 
/*  646 */     accountGetShareInfoExpectFail(shareeAcct, AccountSelector.fromId(shareeAcct.getId()), Boolean.valueOf(true), "invalid request: cannot discover shares on self");
/*      */   }
/*      */   
/*      */   public void modifyCos(Cos cos, String attr, String value) throws ServiceException
/*      */   {
/*  651 */     Map<String, Object> attrs = Maps.newHashMap();
/*  652 */     attrs.put(attr, value);
/*  653 */     ModifyCosRequest modCosReq = new ModifyCosRequest();
/*  654 */     modCosReq.setId(cos.getId());
/*  655 */     modCosReq.setAttrs(attrs);
/*  656 */     ModifyCosResponse modCosResp = (ModifyCosResponse)this.prov.invokeJaxb(modCosReq);
/*  657 */     Assert.assertNotNull(String.format("ModifyCosResponse object when setting %s to %s", new Object[] { attr, value }), modCosResp);
/*      */   }
/*      */   
/*      */   public void checkGetShareInfo(ShareSet expected, List<ShareInfo> shares) {
/*  661 */     if (expected != null) {
/*  662 */       Assert.assertEquals("Number of shares", expected.shares.size(), shares.size());
/*  663 */       for (CutDownShareInfo share : expected.shares) {
/*  664 */         boolean found = false;
/*  665 */         for (ShareInfo aShare : shares) {
/*  666 */           if (share.matches(aShare)) {
/*  667 */             found = true;
/*  668 */             break;
/*      */           }
/*      */         }
/*  671 */         Assert.assertTrue(String.format("no match for '%s' in: %s", new Object[] { share, shares }), found);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   public com.zimbra.soap.admin.message.GetShareInfoResponse adminGetShareInfo(Account acct, ShareSet shareSet) {
/*  677 */     com.zimbra.soap.admin.message.GetShareInfoRequest req = new com.zimbra.soap.admin.message.GetShareInfoRequest(AccountSelector.fromId(acct.getId()));
/*      */     
/*  679 */     com.zimbra.soap.admin.message.GetShareInfoResponse resp = null;
/*      */     try {
/*  681 */       resp = (com.zimbra.soap.admin.message.GetShareInfoResponse)this.prov.invokeJaxb(req);
/*  682 */       Assert.assertNotNull(String.format("GetShareInfoRequest for account %s", new Object[] { acct.getName() }), resp);
/*  683 */       checkGetShareInfo(shareSet, resp.getShares());
/*      */     } catch (ServiceException e) {
/*  685 */       Assert.fail("Unexpected exception while creating mountpoint " + e);
/*      */     }
/*  687 */     return resp;
/*      */   }
/*      */   
/*      */   public void accountGetShareInfoExpectFail(Account acct, AccountSelector owner, Boolean includeSelf, String reason) {
/*  691 */     GranteeChooser grantee = null;
/*      */     try {
/*  693 */       this.prov.invokeJaxbOnTargetAccount(com.zimbra.soap.account.message.GetShareInfoRequest.create(owner, grantee, includeSelf), acct.getId());
/*  694 */       Assert.fail("Unexpected success for GetShareInfoRequest");
/*      */     } catch (ServiceException e) {
/*  696 */       Assert.assertTrue(String.format("Unexpected exception %s (expected msg '%s')", new Object[] { e.getMessage(), reason }), e.getMessage().contains(reason));
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */   public com.zimbra.soap.account.message.GetShareInfoResponse accountGetShareInfo(Account acct, AccountSelector owner, Boolean includeSelf, ShareSet shareSet)
/*      */   {
/*  703 */     com.zimbra.soap.account.message.GetShareInfoResponse resp = null;
/*  704 */     GranteeChooser grantee = null;
/*      */     try {
/*  706 */       resp = (com.zimbra.soap.account.message.GetShareInfoResponse)this.prov.invokeJaxbOnTargetAccount(com.zimbra.soap.account.message.GetShareInfoRequest.create(owner, grantee, includeSelf), acct.getId());
/*      */       
/*  708 */       Assert.assertNotNull(String.format("GetShareInfoRequest for account %s", new Object[] { acct.getName() }), resp);
/*  709 */       checkGetShareInfo(shareSet, resp.getShares());
/*      */     } catch (ServiceException e) {
/*  711 */       Assert.fail("Unexpected exception while creating mountpoint " + e);
/*      */     }
/*  713 */     return resp;
/*      */   }
/*      */   
/*      */   public void createMountpoint(Account acct, String localFolderName, String defaultView, String remoteZimbraId, String remoteFolderId)
/*      */   {
/*  718 */     NewMountpointSpec folderSpec = new NewMountpointSpec(localFolderName);
/*  719 */     folderSpec.setFolderId("1");
/*  720 */     folderSpec.setDefaultView(defaultView);
/*  721 */     folderSpec.setOwnerId(remoteZimbraId);
/*  722 */     folderSpec.setRemoteId(Integer.valueOf(Integer.parseInt(remoteFolderId.substring(remoteFolderId.indexOf(':') + 1))));
/*  723 */     CreateMountpointRequest req = new CreateMountpointRequest(folderSpec);
/*      */     try {
/*  725 */       CreateMountpointResponse resp = (CreateMountpointResponse)this.prov.invokeJaxbOnTargetAccount(req, acct.getId());
/*  726 */       Assert.assertNotNull(String.format("CreateMountpointResponse for account %s folder %s", new Object[] { acct.getName(), localFolderName }), resp);
/*      */     }
/*      */     catch (ServiceException e) {
/*  729 */       Assert.fail("Unexpected exception while creating mountpoint " + e);
/*      */     }
/*      */   }
/*      */   
/*      */   public void grantAccess(Account acct, String id, String granteeType, String granteeName, String perm) {
/*  734 */     FolderActionSelector selector = new FolderActionSelector(id, "grant");
/*  735 */     ActionGrantSelector grant = new ActionGrantSelector(perm, granteeType);
/*  736 */     grant.setDisplayName(granteeName);
/*  737 */     selector.setGrant(grant);
/*  738 */     FolderActionRequest req = new FolderActionRequest(selector);
/*      */     try {
/*  740 */       FolderActionResponse resp = (FolderActionResponse)this.prov.invokeJaxbOnTargetAccount(req, acct.getId());
/*  741 */       Assert.assertNotNull(String.format("FolderActionResponse for account %s", new Object[] { acct.getName() }), resp);
/*      */     } catch (ServiceException e) {
/*  743 */       Assert.fail("Unexpected exception while granting access " + e);
/*      */     }
/*      */   }
/*      */   
/*      */   public String createFolder(Account acct, String name, Byte color, String defaultView) {
/*  748 */     NewFolderSpec newFolderSpec = new NewFolderSpec(name);
/*  749 */     newFolderSpec.setParentFolderId(Integer.toString(1));
/*  750 */     newFolderSpec.setColor(color);
/*  751 */     newFolderSpec.setFlags("#");
/*  752 */     newFolderSpec.setDefaultView(defaultView);
/*  753 */     CreateFolderRequest createFolderReq = new CreateFolderRequest(newFolderSpec);
/*      */     try
/*      */     {
/*  756 */       CreateFolderResponse createFolderResp = (CreateFolderResponse)this.prov.invokeJaxbOnTargetAccount(createFolderReq, acct.getId());
/*  757 */       Assert.assertNotNull(String.format("CreateFolderResponse %s", new Object[] { newFolderSpec.getName() }), createFolderResp);
/*  758 */       return createFolderResp.getFolder().getId();
/*      */     } catch (ServiceException e) {
/*  760 */       Assert.fail("Unexpected exception while creating folder" + e);
/*      */     }
/*  762 */     return null;
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testMailbox() throws Exception {
/*  767 */     ZimbraLog.test.debug("Starting test %s", new Object[] { testName() });
/*  768 */     Domain dom = ensureDomainExists("jaxb.domain2");
/*  769 */     assertNotNull("Domain for jaxb.domain2", dom);
/*  770 */     Account acct = this.prov.createAccount("jaxb1@jaxb.domain2", "test123", null);
/*      */     
/*  772 */     acct = ensureMailboxExists("jaxb1@jaxb.domain2");
/*  773 */     assertNotNull("Account for jaxb1@jaxb.domain2", acct);
/*  774 */     SoapProvisioning.MailboxInfo mbx = this.prov.getMailbox(acct);
/*  775 */     assertNotNull("MailboxInfo for Account=jaxb1@jaxb.domain2", mbx);
/*  776 */     this.prov.deleteAccount(acct.getId());
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testCos() throws Exception {
/*  781 */     ZimbraLog.test.debug("Starting testCos");
/*  782 */     Domain dom = ensureDomainExists("jaxb.cos.domain.example.test");
/*  783 */     assertNotNull("Domain for jaxb.cos.domain.example.test", dom);
/*  784 */     Cos cos = this.prov.createCos("jaxb_cos@jaxb.dl.domain.example.test", null);
/*  785 */     assertNotNull("Cos for jaxb_cos@jaxb.dl.domain.example.test", cos);
/*  786 */     this.prov.renameCos(cos.getId(), "new_jaxb_cos@jaxb.dl.domain.example.test");
/*  787 */     this.prov.copyCos(cos.getId(), "jaxb_cos_copy@jaxb.dl.domain.example.test");
/*  788 */     List<Cos> cosList = this.prov.getAllCos();
/*  789 */     assertNotNull("All Cos", cosList);
/*  790 */     assertTrue("Number of Cos objects=" + cosList.size() + " should be >=1", cosList.size() >= 1);
/*      */     
/*  792 */     this.prov.deleteCos(cos.getId());
/*  793 */     cos = this.prov.get(Key.CosBy.name, "jaxb_cos_copy@jaxb.dl.domain.example.test");
/*  794 */     this.prov.deleteCos(cos.getId());
/*      */   }
/*      */   
/*      */   public void testDistributionList() throws Exception {
/*  798 */     ZimbraLog.test.debug("Starting testDistributionList");
/*  799 */     Domain dom = ensureDomainExists("jaxb.dl.domain.example.test");
/*  800 */     assertNotNull("Domain for jaxb.dl.domain.example.test", dom);
/*  801 */     deleteDlIfExists("jaxb_dl1@jaxb.dl.domain.example.test");
/*  802 */     deleteDlIfExists("jaxb_parentdl@jaxb.dl.domain.example.test");
/*  803 */     DistributionList dl = this.prov.createDistributionList("jaxb_dl1@jaxb.dl.domain.example.test", null);
/*  804 */     assertNotNull("DistributionList for jaxb_dl1@jaxb.dl.domain.example.test", dl);
/*  805 */     this.prov.renameDistributionList(dl.getId(), "new_jaxb_dl1@jaxb.dl.domain.example.test");
/*  806 */     this.prov.addAlias(dl, "alias_4_jaxb_dl1@jaxb.dl.domain.example.test");
/*  807 */     dl = this.prov.get(Key.DistributionListBy.name, "alias_4_jaxb_dl1@jaxb.dl.domain.example.test");
/*  808 */     this.prov.removeAlias(dl, "alias_4_jaxb_dl1@jaxb.dl.domain.example.test");
/*  809 */     String[] members = { "one@example.com", "two@example.test", "three@example.net" };
/*      */     
/*  811 */     String[] rmMembers = { "two@example.test", "three@example.net" };
/*  812 */     this.prov.addMembers(dl, members);
/*  813 */     this.prov.removeMembers(dl, rmMembers);
/*      */     
/*      */ 
/*  816 */     DistributionList dadDl = this.prov.createDistributionList("jaxb_parentdl@jaxb.dl.domain.example.test", null);
/*  817 */     assertNotNull("DistributionList for jaxb_parentdl@jaxb.dl.domain.example.test", dadDl);
/*  818 */     String[] dlMembers = { "one@example.com", "new_jaxb_dl1@jaxb.dl.domain.example.test" };
/*  819 */     this.prov.addMembers(dadDl, dlMembers);
/*  820 */     Map<String, String> via = Maps.newHashMap();
/*  821 */     List<DistributionList> containingDls = this.prov.getDistributionLists(dl, false, via);
/*      */     
/*  823 */     assertEquals("Number of DLs a DL is a member of", 1, containingDls.size());
/*      */     
/*      */ 
/*      */ 
/*  827 */     Account acct = ensureMailboxExists("jaxb1@jaxb.domain2");
/*  828 */     String[] dlAcctMembers = { "jaxb1@jaxb.domain2" };
/*  829 */     this.prov.addMembers(dadDl, dlAcctMembers);
/*  830 */     containingDls = this.prov.getDistributionLists(acct, false, via);
/*      */     
/*  832 */     assertEquals("Number of DLs an acct is a member of", 1, containingDls.size());
/*      */     
/*      */ 
/*  835 */     List<DistributionList> dls = this.prov.getAllDistributionLists(dom);
/*  836 */     assertNotNull("All DLs", dls);
/*  837 */     assertTrue("Number of DL objects=" + dls.size() + " should be >=2", dls.size() >= 2);
/*      */     
/*  839 */     this.prov.deleteDistributionList(dadDl.getId());
/*  840 */     this.prov.deleteDistributionList(dl.getId());
/*      */   }
/*      */   
/*      */   public void testCalendarResource() throws Exception {
/*  844 */     ZimbraLog.test.debug("Starting testCalendarResource");
/*  845 */     deleteCalendarResourceIfExists("jaxb1@jaxb.calr.domain.example.test");
/*  846 */     deleteDomainIfExists("jaxb.calr.domain.example.test");
/*  847 */     Domain dom = this.prov.createDomain("jaxb.calr.domain.example.test", null);
/*  848 */     assertNotNull("Domain for jaxb.domain1", dom);
/*  849 */     Map<String, Object> attrs = Maps.newHashMap();
/*  850 */     attrs.put("displayName", "JAXB Test CalResource");
/*  851 */     attrs.put("zimbraCalResType", "Location");
/*  852 */     attrs.put("zimbraCalResLocationDisplayName", "Harare");
/*  853 */     CalendarResource calRes = this.prov.createCalendarResource("jaxb1@jaxb.calr.domain.example.test", "test123", attrs);
/*      */     
/*  855 */     assertNotNull("CalendarResource on create", calRes);
/*  856 */     this.prov.renameCalendarResource(calRes.getId(), "new_jaxb1@jaxb.calr.domain.example.test");
/*  857 */     List<CalendarResource> resources = this.prov.getAllCalendarResources(dom, Provisioning.getInstance().getLocalServer());
/*      */     
/*  859 */     assertNotNull("CalendarResource List for getAll", resources);
/*  860 */     assertEquals("CalendarResource list size", 1, resources.size());
/*  861 */     calRes = this.prov.get(Key.CalendarResourceBy.id, calRes.getId());
/*  862 */     this.prov.deleteCalendarResource(calRes.getId());
/*      */   }
/*      */   
/*      */   public void testQuotaUsage() throws Exception {
/*  866 */     ZimbraLog.test.debug("Starting testQuotaUsage");
/*  867 */     List<com.zimbra.cs.account.soap.SoapProvisioning.QuotaUsage> quotaUsages = this.prov.getQuotaUsage(Provisioning.getInstance().getLocalServer().getName());
/*      */     
/*  869 */     assertNotNull("QuotaUsage List", quotaUsages);
/*  870 */     assertTrue("Number of QuotaUsage objects=" + quotaUsages.size() + " should be >1", quotaUsages.size() > 1);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void DISABLED_testGetServerNIfs()
/*      */     throws Exception
/*      */   {
/*  879 */     ZimbraLog.test.debug("Starting testGetServerNIfs");
/*  880 */     Server svr = Provisioning.getInstance().getLocalServer();
/*  881 */     GetServerNIfsRequest req = new GetServerNIfsRequest(null, com.zimbra.soap.admin.type.ServerSelector.fromId(svr.getId()));
/*      */     
/*  883 */     GetServerNIfsResponse resp = (GetServerNIfsResponse)this.prov.invokeJaxb(req);
/*  884 */     assertNotNull("GetServerNIfsResponse", resp);
/*  885 */     List<com.zimbra.soap.admin.type.NetworkInformation> nisList = resp.getNetworkInterfaces();
/*  886 */     assertNotNull("NetworkInfomation List", nisList);
/*      */   }
/*      */   
/*      */   public void testLicenseInfo() throws Exception {
/*  890 */     ZimbraLog.test.debug("Starting testLicenseInfo");
/*  891 */     GetLicenseInfoRequest req = new GetLicenseInfoRequest();
/*  892 */     GetLicenseInfoResponse resp = (GetLicenseInfoResponse)this.prov.invokeJaxb(req);
/*  893 */     assertNotNull("GetLicensInfoResponse", resp);
/*  894 */     LicenseExpirationInfo expires = resp.getExpiration();
/*  895 */     assertNotNull("Expiration Info", expires);
/*  896 */     assertNotNull("getDate result", expires.getDate());
/*      */   }
/*      */   
/*      */   public void testVersionInfo() throws Exception {
/*  900 */     ZimbraLog.test.debug("Starting testVersionInfo");
/*  901 */     GetVersionInfoRequest req = new GetVersionInfoRequest();
/*  902 */     GetVersionInfoResponse resp = (GetVersionInfoResponse)this.prov.invokeJaxb(req);
/*  903 */     assertNotNull("GetLicensInfoResponse", resp);
/*  904 */     VersionInfo info = resp.getInfo();
/*  905 */     assertNotNull("VersionInfo", info);
/*  906 */     info.getType();
/*  907 */     assertNotNull("getVersion result", info.getVersion());
/*  908 */     assertNotNull("getRelease result", info.getRelease());
/*  909 */     assertNotNull("getBuildDate result", info.getBuildDate());
/*  910 */     assertNotNull("getHost result", info.getHost());
/*  911 */     assertNotNull("getMajorVersion result", info.getMajorVersion());
/*  912 */     assertNotNull("getMinorVersion result", info.getMinorVersion());
/*  913 */     assertNotNull("getMicroVersion result", info.getMicroVersion());
/*  914 */     assertNotNull("getPlatform result", info.getPlatform());
/*  915 */     assertNotNull("getBuildDate result", info.getBuildDate());
/*      */   }
/*      */   
/*      */   public void testIndex() throws Exception {
/*  919 */     ZimbraLog.test.debug("Starting testIndex");
/*  920 */     Account acct = ensureMailboxExists("jaxb1@jaxb.domain2");
/*  921 */     SoapProvisioning.ReIndexInfo info = this.prov.reIndex(acct, "start", null, null);
/*  922 */     assertNotNull("ReIndexInfo", info);
/*  923 */     assertNotNull("getStatus result", info.getStatus());
/*      */     
/*      */ 
/*  926 */     com.zimbra.cs.account.soap.SoapProvisioning.VerifyIndexResult ndxRes = this.prov.verifyIndex(acct);
/*  927 */     assertNotNull("VerifyIndexResult", ndxRes);
/*  928 */     this.prov.deleteMailbox(acct.getId());
/*      */   }
/*      */   
/*      */   public void testMboxCounts() throws Exception {
/*  932 */     ZimbraLog.test.debug("Starting testMboxCounts");
/*  933 */     Account acct = ensureMailboxExists("jaxb1@jaxb.domain2");
/*  934 */     long quotaUsed = this.prov.recalculateMailboxCounts(acct);
/*  935 */     assertTrue("quota used=" + quotaUsed + " should be >= =", quotaUsed >= 0L);
/*      */   }
/*      */   
/*      */   public void testFlushCache() throws Exception {
/*  939 */     ZimbraLog.test.debug("Starting testFlushCache");
/*  940 */     ensureDomainExists("jaxb.domain1");
/*  941 */     this.prov.flushCache(CacheEntryType.domain, null);
/*      */   }
/*      */   
/*      */   public void testGetAllRights() throws Exception {
/*  945 */     ZimbraLog.test.debug("Starting testGetAllRights");
/*  946 */     List<Right> rights = this.prov.getAllRights("account", true, "USER");
/*      */     
/*  948 */     assertNotNull("getAllRight returned list", rights);
/*  949 */     assertTrue("Number of rights objects=" + rights.size() + " should be > 3", rights.size() > 3);
/*      */   }
/*      */   
/*      */   public void testGetAllEffectiveRights() throws Exception
/*      */   {
/*  954 */     ZimbraLog.test.debug("Starting testGetAllEffectiveRights");
/*  955 */     RightCommand.AllEffectiveRights aer = this.prov.getAllEffectiveRights(null, null, null, false, true);
/*      */     
/*  957 */     assertNotNull("AllEffectiveRights", aer);
/*      */   }
/*      */   
/*      */   public void testGetEffectiveRights() throws Exception {
/*  961 */     ZimbraLog.test.debug("Starting testGetEffectiveRights");
/*  962 */     com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveRights er = this.prov.getEffectiveRights("account", com.zimbra.soap.type.TargetBy.name, "admin", GranteeSelector.GranteeBy.name, "admin", true, true);
/*      */     
/*      */ 
/*      */ 
/*  966 */     assertNotNull("EffectiveRights", er);
/*      */   }
/*      */   
/*      */   public void testGetRightsDoc() throws Exception {
/*  970 */     ZimbraLog.test.debug("Starting testGetRightsDoc");
/*  971 */     Map<String, List<Provisioning.RightsDoc>> map = this.prov.getRightsDoc(null);
/*  972 */     assertTrue("Map size=" + map.size() + " should be >= 1", map.size() >= 1);
/*      */     
/*  974 */     String[] pkgs = { "com.zimbra.cs.service.admin" };
/*  975 */     map = this.prov.getRightsDoc(pkgs);
/*  976 */     assertEquals("Map for specified set of pkgs", 1, map.size());
/*  977 */     boolean seenTstRight = false;
/*  978 */     for (String key : map.keySet()) {
/*  979 */       assertEquals("key to map", pkgs[0], key);
/*  980 */       for (Provisioning.RightsDoc rightsDoc : (List)map.get(key)) {
/*  981 */         assertNotNull("rightsDoc cmd name", rightsDoc.getCmd());
/*  982 */         if (rightsDoc.getCmd().equals("AddAccountAliasRequest")) {
/*  983 */           seenTstRight = true;
/*  984 */           assertEquals("Notes number", 3, rightsDoc.getNotes().size());
/*  985 */           assertEquals("Rights number", 3, rightsDoc.getRights().size());
/*      */         }
/*      */       }
/*      */     }
/*  989 */     assertTrue("AddAccountAliasRequest right in report", seenTstRight);
/*      */   }
/*      */   
/*      */   public void testGetRight() throws Exception {
/*  993 */     ZimbraLog.test.debug("Starting testGetRight");
/*  994 */     Right right = this.prov.getRight("adminConsoleAccountRights", true);
/*  995 */     assertNotNull("Right", right);
/*  996 */     RightClass rightClass = right.getRightClass();
/*  997 */     assertEquals("right RightClass", rightClass, RightClass.ADMIN);
/*  998 */     assertEquals("right Name", "adminConsoleAccountRights", right.getName());
/*      */   }
/*      */   
/*      */   public void testHealth() throws Exception {
/* 1002 */     ZimbraLog.test.debug("Starting testHealth");
/* 1003 */     assertTrue(this.prov.healthCheck());
/*      */   }
/*      */   
/*      */   public void testIdentities() throws Exception {
/* 1007 */     ZimbraLog.test.debug("Starting testIdentities");
/* 1008 */     Account acct = ensureAccountExists("jaxb1@jaxb.domain2");
/* 1009 */     List<Identity> identities = this.prov.getAllIdentities(acct);
/* 1010 */     assertEquals("Number of identities for new acct", 1, identities.size());
/* 1011 */     Map<String, Object> attrs = Maps.newHashMap();
/* 1012 */     attrs.put("zimbraPrefFromAddress", "identity_4_jaxb1@jaxb.domain2");
/* 1013 */     Identity newId = this.prov.createIdentity(acct, "altIdentity", attrs);
/* 1014 */     assertNotNull("New identity", newId);
/* 1015 */     identities = this.prov.getAllIdentities(acct);
/* 1016 */     assertEquals("Number of identities after add", 2, identities.size());
/* 1017 */     this.prov.deleteIdentity(acct, "altIdentity");
/* 1018 */     identities = this.prov.getAllIdentities(acct);
/* 1019 */     assertEquals("Number of identities after delete", 1, identities.size());
/*      */   }
/*      */   
/*      */   public static void main(String[] args) throws Exception
/*      */   {
/* 1024 */     TestUtil.cliSetup();
/* 1025 */     TestUtil.runTest(TestJaxbProvisioning.class);
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestJaxbProvisioning.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */